package com.util;

import com.generator.entity.Reply;
import com.generator.entity.Send;
import com.generator.mapper.ReplyMapper;
import com.generator.mapper.SendMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * @Author: htj
 * @Date: 2021/10/2 0002 上午 1:41
 * 入库模块
 */

@Component
public class IntoDB {

    @Autowired
    private SendMapper sendMapper;

    @Autowired
    private ReplyMapper replyMapper;

    //请求信息入库
    public int insertSend(int api_id, int thirdParty_id, String content) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        Send send = new Send();
        send.setThirdpartyId(thirdParty_id);
        send.setApiId(api_id);
        send.setContent(content);
        send.setRequestTime(timestamp);
        sendMapper.insert(send);//异常处理吗？
        return send.getId();//直接可以拿到新的自增id！
    }

    //返回信息入库
    public void insertReturn(Reply result) {
        replyMapper.insert(result);//异常处理吗？
    }

}
